using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public int speed = 100;
    public BaseTank tank;
    private GameObject bullet;
    Rigidbody rb;
    // Start is called before the first frame update
    public virtual void Init()
    {
        var bulletRes = ResManager.LoadPrefab("Prefabs/Bullet");
        bullet = Instantiate(bulletRes);
        bullet.transform.parent = transform;
        bullet.transform.localPosition = Vector3.zero;
        bullet.transform.localEulerAngles = Vector3.zero;

        rb = gameObject.AddComponent<Rigidbody>();
        rb.useGravity = false;
    }
    private void Update()
    {
        transform.position += transform.forward * speed * Time.deltaTime;
    }
    private void OnCollisionEnter(Collision collision)
    {
        var other = collision.gameObject;
        BaseTank hitTank = other.GetComponent<BaseTank>();
        if (hitTank == tank)
        {
            return;
        }
        if(hitTank != null)
        {
            hitTank.Attacked(35);
        }
        //GameObject explode = ResManager.LoadPrefab("Fire");
        //Instantiate(explode, transform.position, transform.rotation);
        Destroy(gameObject);
    }
}
